﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Homework5._6
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("请输入第一个正整数：");
            bool can1 = int.TryParse(Console.ReadLine(),out int Number1);
            while (can1 == false|| Number1<=0)
            {
                Console.Write("输入错误，请重新输入第一个正整数：");
                can1 = int.TryParse(Console.ReadLine(), out Number1);
            }
            Console.Write("请输入第二个正整数：");
            bool can2 = int.TryParse(Console.ReadLine(), out int Number2);
            while (can2 == false || Number2 <= 0)
            {
                Console.Write("输入错误，请重新输入第二个正整数：");
                can2 = int.TryParse(Console.ReadLine(), out Number2);
            }
            //辗转相除法求最大公约数，若求最小公倍数则为Number1*Number2/Number3
            int MyMin = Math.Min(Number1, Number2);
            int MyMax = Math.Max(Number1, Number2);
            while (MyMax % MyMin !=0)
            {
                int a = MyMin;
                int b = MyMax % MyMin;
                MyMax = Math.Max(a, b); 
                MyMin = Math.Min(a, b);  
            }
            int Number3 = MyMin;
            Console.WriteLine($"两正整数的最大公约数为：{Number3}");
            Console.ReadKey();

        }
    }
}
